package com.goldenautumn.prefabricate.widget.dialog

import android.view.Gravity
import android.view.View
import android.view.Window
import android.view.WindowManager
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.ScreenUtils
import com.goldenautumn.prefabricate.R
import com.goldenautumn.prefabricate.business.user.UserViewModel
import com.goldenautumn.prefabricate.databinding.DialogCountryBinding
import qncx.external.common.widget.dialog.BaseDialog

class CountrySelectDialog constructor(val type: Int, val block: () -> Unit) :
    BaseDialog<DialogCountryBinding>(qncx.external.common.R.style.BottomDialogs) {

    private val mUserModel by viewModels<UserViewModel>()

    private val mAdapter by lazy {
        CountryAdapter()
    }

    override val layoutRes: Int
        get() = R.layout.dialog_country

    override fun onStart() {
        super.onStart()
        val window: Window? = dialog?.window
        val params: WindowManager.LayoutParams? = window?.attributes
        params?.dimAmount = dimAmount
        params?.width = WindowManager.LayoutParams.MATCH_PARENT
        params?.height = (ScreenUtils.getScreenHeight() * 0.9).toInt()
        params?.gravity = Gravity.BOTTOM
        window?.attributes = params
    }

    override suspend fun bindView(view: View): View {
        mBinding.toolbar.setNavigationOnClickListener { dismiss() }

        mBinding.countryRv.layoutManager = LinearLayoutManager(context)
        mBinding.countryRv.adapter = mAdapter

        mAdapter.submitList(arrayListOf("", "", "", "", "", "", "", "", "", ""))

        mAdapter.setOnItemClickListener { _, _, position ->
            mAdapter.selectPosition = position
            mAdapter.notifyDataSetChanged()
        }

        return view
    }
}